package ink.xiaobaibai.controller.monthly;

import ink.xiaobaibai.annotation.InsidePublicResources;
import ink.xiaobaibai.autoConfig.roleResources.ResourcesRoleMapping;
import ink.xiaobaibai.common.MonthlyAddDayBo;
import ink.xiaobaibai.common.MyRole;
import ink.xiaobaibai.multipleClick.ForbidMultipleClick;
import ink.xiaobaibai.response.ResponseFormat;
import ink.xiaobaibai.service.monthly.IOrderAddDayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 月费时间延长接口
 * @author: 小白白
 * @create: 2021-06-10
 **/

@Api(tags = "月费时间延长接口")
@RestController
@RequestMapping("/add-day")
@InsidePublicResources
@CrossOrigin
public class AddDayController {

    @Autowired
    private IOrderAddDayService orderAddDayService;

    /**
     * 查看自己的延长列表
     */
    @GetMapping("/list")
    @ApiOperation("查看自己的延长列表(管理员和权限人员可以看到所有)")
    public ResponseFormat list(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        return ResponseFormat.success(this.orderAddDayService.getAddDayListAllRole(pageNum, pageSize));
    }

    /**
     * 业务员申请将orderId延长多少天...
     */
    @PostMapping("/addDay")
    @ApiOperation("业务员申请将包月天数延长多少天")
    public ResponseFormat addDay(@RequestBody @Validated MonthlyAddDayBo addDayBo) {
        return ResponseFormat.success(this.orderAddDayService.addOrderDay(addDayBo.getOrderId(), addDayBo.getDay(), addDayBo.getReason()));
    }

    /**
     * 经理同意
     */
    @PostMapping("/agent-agree")
    @ApiOperation("经理同意此申请")
    public ResponseFormat agentAgree(@RequestParam Integer id) {
        return ResponseFormat.success(this.orderAddDayService.agreeAddDayByAgent(id));
    }

    /**
     * 经理拒绝
     */
    @PostMapping("/agent-refuse")
    @ApiOperation("经理拒绝此申请")
    public ResponseFormat agentRefuse(@RequestParam Integer id) {
        return ResponseFormat.success(this.orderAddDayService.refuseAddDayByAgent(id));
    }

    /**
     * 管理同意
     */
    @PostMapping("/admin-agree")
    @ApiOperation("管理同意此申请")
    @ResourcesRoleMapping(resourceName = "管理同意月费加天数", includeRoleNames = {MyRole.ADMIN, MyRole.POWER_MONTHLY})
    @ForbidMultipleClick(key = "#id")
    public ResponseFormat adminAgree(@RequestParam Integer id) {
        return ResponseFormat.success(this.orderAddDayService.agreeAddDayByAdmin(id));
    }

    /**
     * 管理拒绝
     */
    @PostMapping("/admin-refuse")
    @ResourcesRoleMapping(resourceName = "管理拒绝月费加天数", includeRoleNames = {MyRole.ADMIN, MyRole.POWER_MONTHLY})
    @ApiOperation("管理拒绝此申请")
    public ResponseFormat adminRefuse(@RequestParam Integer id) {
        return ResponseFormat.success(this.orderAddDayService.refuseAddDayByAdmin(id));
    }

}
